package org.zxy.jaxb;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import org.apache.cxf.service.invoker.Factory;

import com.sun.jmx.remote.internal.Unmarshal;

public class JaxbClient {
	public static void main(String[] args) throws Exception {
		Parent parent = new Parent();
		
		parent.setParentName("zhangsan");
		parent.setParentAddress("beijing");
		
		Boss boss = new Boss();
		
		boss.setBossName("lisi");
		boss.setBossAge(20);
		boss.setParent(parent);
		
		Teacher teacher = new Teacher();
		
		teacher.setTeacherName("wangwu");
		teacher.setTeacherAddress("shanghai");
		teacher.setBoss(boss);
		
		Student student = new Student();
		
		student.setStudentAge(15);
		student.setStudentAddress("tianjin");
		student.setTeacher(teacher);
		
		JAXBContext context = JAXBContext.newInstance(Student.class);
		Marshaller marshaller = context.createMarshaller();
		marshaller.marshal(student, System.out);
		
		System.out.println("--------");
		
		Unmarshaller unmarshaller = context.createUnmarshaller();
		Student student2 = (Student) unmarshaller.unmarshal(new File("E:\\hanzaki\\project\\ws\\ws-cxf\\src\\main\\resources\\test.xml"));
		
		System.out.println(student2.getStudentAddress()+" ,"+student2.getTeacher().getTeacherAddress()+
				" ,"+student2.getTeacher().getBoss().getBossName());
	}
}
